<template>
	<view class="page">
		<!-- 顶部头部 -->
		<view class="top_navigation">
			<view class="status_bar" :style="{height:barHei+'px'}">
				<!-- 这里是状态栏 -->
			</view>
			<view class="navigation flex-c-c-c">
				氧发堂首页
				<image src="/static/logo.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="status_bar" :style="{height:barHei+'px'}">
			<!-- 这里是占位的状态栏 -->
		</view>
		<!-- 定位+消息 -->
		<view class="location_message flex-r-b-c">
			<view class="position flex-r-s-c" @click="store_show=true">
				<image src="../../../static/icon/position.png" style="height: 30px;" mode="heightFix"></image>
				<view class="position_text">
					<view class="position_text1 flex-r-s-c">{{zz_store_obj.name||store_list[0].name}}
						<image src="/static/icon/rightArrow.png" style="height: 10px;margin-left: 5px;"
							mode="heightFix"></image>
					</view>
					<!-- <text>距离{{zz_store_obj.distance||store_list[0].distance}}km</text> -->
					<text>距离{{zz_store_obj.distance}}km</text>
				</view>
			</view>
			<navigator url="/message/newsList/newsList" class="message_red" v-if="!isClose">
				<image src="/static/icon/message.png" mode="heightFix" style="height: 20px;"></image>
				<view v-if="message_show"></view>
			</navigator>
			<view class="btn" @tap.stop="goExternal" v-else
				style="width: 200rpx; height: 60rpx;  background-color: #45806E; border-radius: 60rpx; color: #FFFFFF; text-align: center; line-height: 60rpx; font-size: 24rpx; font-weight: 500;">
				关注公众号</view>
		</view>
		<!-- 轮播 -->
		<!-- <view class="swiper_bar" style="height: 850rpx;">
			<u-swiper :list="list" height="850"  name='img' @click="swiper_fn" img-mode="widthFix"></u-swiper>
		</view> -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
			:style="{height:sweiperHeight+'px'}" @change="sweiperHeightFn" :circular="true">
			<swiper-item v-for="(v,i) in list" :key="i">
				<view class="swiper-item">
					<image :src="v.img" mode="widthFix" style="width: 750rpx;" :ref="'imgs'+i" @load="imgs"
						:data-index='i' @click="swiper_fn(i)"></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- 轮播下的选择栏 -->
		<view class="flex-r-c-c" style="background-color: #FFFFFF;">
			<view v-for="(v,i) in jump" :key='i' :open-type="v.type" @tap.stop="goUrl(v.path)"
				class="menu_taber flex-c-c-c">
				<image :src="v.icon" mode="widthFix" style="width:55px;"></image>
				<text>{{v.name}}</text>
			</view>
		</view>
		<!-- 活动barBer -->
		<!-- <view class="flex-c-c-c" style="width: 750rpx;height: 198rpx;">
			<view style="height: 198rpx;width: 700rpx;">
				<u-swiper :list="jump1" height="198" name='img' @click="swiper_fn1" :mode="jump1.length>1?'dot':'none'">
				</u-swiper>
			</view>
		</view> -->
		<view class="flex-c-c-c" style="width: 750rpx;height: auto;padding:20rpx;">
			<view class="" v-for="(v,i) in jump1" :key="i" style="width:710rpx;height: auto;">
				<view class="" style="width: 710rpx;height: auto;" v-if="v.activity_type==4">
					<image :src="base.imgUrl+v.activity_imgae" mode="widthFix" style="width: 100%;"
					@click="is_coupon_show=true;coupon_obj={...v,price:v.coupon_price,id:v.coupon_id}"></image>
				</view>
				
				<view class="flex-r-b-c" v-else @click="jumps_activ(v)"
					style="height: 260rpx;background-color: #FFFFFF;margin:7px 0px;border-radius: 6px;width:710rpx;padding:20rpx;">
					<view style="position: relative;border-radius: 6px;">
						<image :src="base.imgUrl+v.image" mode=""
							style="width:220rpx;height: 220rpx;border-radius: 6px;">
						</image>
						<view class="flex-c-c-c" v-if="v.user_type == 1 || v.user_type == 2"
							style="position: absolute;left: 0px;top: 0px;width: 90rpx;height: 40rpx;border-radius: 10rpx 20rpx 20rpx 0rpx;" :style="{background: v.user_type == 1 ? '#FC0D1B' : v.user_type == 2 ? '#68B496' : '' }">
							<text style="color:#FFFFFF;font-size: 20rpx;">{{v.user_type == 1 ? '新用户' : v.user_type == 2 ? '老用户' : '' }}</text>
						</view>
					</view>
					
					<!-- <view class="flex-c-b-s" style="height: 194rpx;margin-left:12px;width:420rpx;">
						<view :class="[v.activity_type==1?'flex-r-b-c':'flex-r-s-c']" style="width:100%">
							<text style="color: #3B3B3B;font-size: 32rpx;flex: 1; font-weight: 800;"
								class="one-line-ellipsis">{{v.name}}</text>
							<view class="flex-r-s-c" v-if="v.activity_type==1">
								<image src="/static/icon/time.png" mode="widthFix" style="width: 40rpx;"></image>
								<countDown v-if="Math.round(new Date() / 1000)>v.start_time" :start_time="v.start_time"
									:end_time="v.end_time" color="#45806E;" font_size="28rpx"></countDown>
								<text style="color: #45806E;font-size: 28rpx;" v-else>未开始</text>
							</view>
							<view class="flex-c-c-c" v-else
								style="width: 108rpx;height: 40rpx;background: #45806e33;border-radius: 8rpx;color: #45806E;font-size: 20rpx;margin-left: 20rpx;">
								{{v.activity_type==2?'拼团有礼': v.value}}
							</view>
						</view>
						<text class="two-line-ellipsis"
							style="color: #959595;font-size: 24rpx;">{{v.activity_type==1?(Math.round(new Date() / 1000)>v.start_time?'正在抢购中':`${$u.timeFormat(v.start_time, isToday(v.start_time)?'hh:MM':'mm-dd hh:MM')}即将开抢`):v.activity_type==2?`已有${v.cnum}人已成团数${v.num}`:v.describe}}</text>
						<view class="flex-r-b-c" style="width: 100%;">
							<view class="flex-r-s-c">
								<text
									style="color:#5D5D5D;font-size: 24rpx;margin-left: 10rpx;">{{v.activity_type==1?'秒杀价':v.activity_type==2?'拼团价':'抢购价'}}</text>
								<text style="color: #FF6C1D;font-size: 34rpx;">￥{{v.price}}</text>
							</view>
							<view class="flex-r-c-c"
								style="width: 166rpx;height: 62rpx;border-radius: 8rpx;font-size: 28rpx;"
								:style="{color:v.activity_type==1?Math.round(new Date() / 1000)>v.start_time?'#FFF':'#999':'#FFF',backgroundColor:v.activity_type==1?Math.round(new Date() / 1000)>v.start_time?'#FF6C1D':'#E3E3E3':'#FF6C1D'}">
								{{v.activity_type==1?'立即秒杀':v.activity_type==2?'立即拼团':'立即抢购'}}
								<u-icon name="arrow-right"
									:color="v.activity_type==1?Math.round(new Date() / 1000)>v.start_time?'#FFF':'#999999':'#FFF'"
									size="20"></u-icon>
							</view>
						</view>
					</view> -->
					<view class="flex-c-b-s" style="height: 194rpx; margin-left: 12px; width: 400rpx;">
						
						<view class="flex-r-b-c" style="width: 100%;">
							<text class="one-line-ellipsis"
								style="color: #3B3B3B; font-size: 32rpx; font-weight: 800;">{{v.name}}</text>
							<view class="flex-c-c-c" v-if="v.activity_type == 2 || v.activity_type == 3"
								style="width: 108rpx; height: 40rpx; background-color: #45806e33; border-radius: 8rpx; color: #45806E; font-size: 20rpx; margin-left: 20rpx;">
								{{v.activity_type == 2 ? '拼团有礼' : v.activity_type == 3 ? v.value : ''}}
							</view>
						</view>
						
						<view class="flex-r-s-c" v-if="v.activity_type == 1 || v.activity_type == 3">
							<image src="/static/icon/time.png" mode="widthFix" style="width: 40rpx;"></image>
							<countDown v-if=" Math.round(new Date() / 1000) > v.start_time" :start_time="v.start_time" :end_time="v.end_time" color="#45806E" font_size="28rpx"></countDown>
							<text style="color: #45806E;font-size: 28rpx;" v-else>未开始</text>
						</view>
						
						<text v-if="v.activity_type == 2" class="two-line-ellipsis" style="color: #959595; font-size: 24rpx;">{{`已有${v.cnum}人已成团数${v.num}`}}</text>
						
						<view class="flex-r-b-c" style="width: 100%;">
							<view class="flex-r-s-c">
								<text style="color: #5D5D5D; font-size: 24rpx; margin-left: 10rpx;">{{v.activity_type==1?'抢购价':v.activity_type==2?'拼团价':'抢购价'}}</text>
								<text style="color: #FF6C1D; font-size: 32rpx;">¥{{v.price}}</text>
							</view>
							<view class="flex-r-c-c"
								style="width: 166rpx;height: 62rpx;border-radius: 8rpx;font-size: 28rpx;"
								:style="{color:v.activity_type==1?Math.round(new Date() / 1000)>v.start_time?'#FFF':'#999':'#FFF',backgroundColor:v.activity_type==1?Math.round(new Date() / 1000)>v.start_time?'#FF6C1D':'#E3E3E3':'#FF6C1D'}">
								{{v.activity_type==1?'立即抢购':v.activity_type==2?'立即拼团':'立即抢购'}}
								<u-icon name="arrow-right"
									:color="v.activity_type==1?Math.round(new Date() / 1000)>v.start_time?'#FFF':'#999999':'#FFF'"
									size="20"></u-icon>
							</view>
						</view>
					</view>
					
					
				</view>
			</view>

		</view>
		<view v-for="(item,index) in arr" :key='index'>
			<!-- 标题 -->
			<view :class="[item.is_more!=1?'flex-c-c-c':'flex-r-b-c']" style="height: 50px;padding: 0 10px;">
				<text v-if="item.is_more==1"></text>
				<text style="color: #363636;font-size: 18px;font-weight: 800;">{{item.name}}</text>
				<navigator url="/pages/tabBar/service/service" class="flex-r-b-c" v-if="item.is_more==1">
					<text style="color: #A3A3A3;font-size: 14px;">更多</text>
					<image src="../../../static/icon/rightArrow.png" mode="widthFix"
						style="width: 6px;margin-left: 5px;">
					</image>
				</navigator>
			</view>
			<!--商品 -->
			<view class="felx-c-c-c" style="padding:0px 10px;">
				<navigator class="flex-r-b-c" v-for="(v,i) in item.goods" :key="i" open-type="navigate"
					:url="'/order/activityDetails/activityDetails?id='+v.goods_id+'&type=1'"
					style="padding:20rpx;height: 230rpx;background-color: #FFFFFF;margin:7px 0px;border-radius: 6px;">
					<view style="position: relative;width:280rpx;height: 210rpx;border-radius: 6px;">
						<image :src="base.imgUrl+v.image" mode=""
							style="width:220rpx;height: 220rpx;border-radius: 6px;">
						</image>
						<view class="flex-c-c-c" v-if="item.type==2"
							style="position: absolute;left: 7px;top: 7px;width: 49px;height: 21px;border-radius: 13px;background-color: #FFFFFF;">
							<text style="color: #FF7A08;font-size: 13px;">抢购</text>
						</view>
					</view>
					<view class="flex-c-b-s" style="height: 108px;margin-left:12px;width: 420rpx;">
						<view class="flex-r-b-c" style="width: 100%">
							<text style="color: #555555;font-size: 32rpx;font-weight: 800;">{{v.name}}</text>
							<button @tap.stop="shareClick(item,v)" :open-type="isShare ? 'share' : '' "
								class="btn_none flex-c-c-c" style="width: 80rpx;height:60rpx;" v-if="item.is_share==1">
								<image src="/static/icon/share.png" mode="widthFix" style="width: 30rpx;">
								</image>
							</button>
						</view>
						<text class="two-line-ellipsis" style="color: #555555;font-size: 24rpx;">{{v.describe}}</text>
						<view class="flex-r-s-e" style="align-items:baseline!important">
							<text style="color: #FF6C1D;font-size: 36rpx;">￥ {{v.price}}</text>
							<text style="color:#C3C3C3;font-size: 20rpx;margin-left: 10rpx;"
								v-if="v.orginal_price != 0">原价</text>
							<text style="color: #C3C3C3;font-size:28rpx;text-decoration:line-through;margin-left: 8rpx;"
								v-if="v.orginal_price != 0">{{v.orginal_price}}</text>
						</view>
					</view>
				</navigator>
			</view>
		</view>
		<view class="safe-paddings" style="width: 750rpx;background-color: #FFF0;"></view>
		<!-- 客服 -->
		<view style="position: fixed;z-index: 2; border-radius: 50%;overflow:hidden;"
			:style="'left:'+ moveX + 'px;top:' + moveY +'px;'">
			<button @touchstart="drag_start" @touchmove.stop.prevent="drag_hmove" @tap.stop="customerService"
				class="btn_none flex-c-c-c" session-from=''>
				<image src="/static/icon/customerService.png" mode="widthFix" style="width: 44px;"></image>
			</button>
		</view>

		<!-- 关注公众号 -->
		<!-- 	<view v-if="isClose"
			style="width: 100vw; height: 160rpx; background: #F4F4F4; box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.08); border-radius: 4rpx; position: fixed;"
			class="isClose">
			<u-icon style="position: absolute; right: 10rpx; top: 10rpx; box-sizing: border-box; padding: 10rpx;" name="close" color="#C9C9C9" size="25"
				@tap="isClose = false"></u-icon>
			<view class="flex-r-b-c" style="height: 100rpx;width: 100%;">
				<view class="">
					<image src="../../../static/logo.png" mode="widthFix" style="width: 100rpx; height: 100rpx;">
					</image>
				</view>
				<view class="flex-r-b-s" style="width: calc(100% - 120rpx);">
					<view class="flex-c-b-s" style="width: 100%;height:calc(200rpx - 60rpx );padding:25rpx 0;">
						<view class="name" style="font-size: 32rpx; font-weight: 600; color: #4B4B4B;">氧发堂</view>
						<view class="text"
							style="font-size: 22rpx; font-weight: 400; color: #999999; margin-top: 18rpx;">
							天然的更健康，植物染发就选氧发堂！</view>
					</view>
					<view class="flex-c-c-c" style="height:calc(200rpx - 60rpx );">
						<view class="btn" @tap.stop="goExternal"
							style="margin-right: 50rpx; width: 120rpx; height: 60rpx;  background-color: #45806E; border-radius: 60rpx; color: #FFFFFF; text-align: center; line-height: 60rpx; font-size: 24rpx; font-weight: 500;">
							关注</view>
					</view>
				</view>
			</view>
		</view> -->
		<!-- 获取位置 -->
		<!-- 	<view style="width: 750rpx;position: fixed;left: 0;top: 0;z-index:10099" @click="store_fn()"
			:style="{height:hei+'px'}" v-if="store_views"></view> -->
		<!-- 地址选择 -->
		<u-popup v-model="store_show" mode="bottom" border-radius="50" width="100vw" height="1030rpx" z-index='10000'
			:mask-close-able="userInfo?true:false">
			<view class="flex-r-b-c" style="width: 100%;height:110rpx;padding: 0px 16px;">
				<text style="color: #333333;font-size: 18px;font-weight: bold;">选择门店</text>
				<!-- <text @click="userInfo?store_true():getUserInfo()" style="color: #333333;font-size: 15px;">确定</text> -->
			</view>
			<view style="width:100%;height:76rpx;margin-bottom: 24rpx;" class="flex-c-c-c">
				<view class="flex-r-b-c" style="width:686rpx;height:76rpx;">
					<view class="flex-r-s-c" style="width: 528rpx;height:76rpx;">
						<u-search style="width: 100%;" placeholder="请输入门店名称" :show-action="false"
							v-model="store_obj.seach"></u-search>
					</view>
					<view class="flex-c-c-c"
						style="width: 130rpx;height: 62rpx;border-radius:8rpx;background-color: #45806E;">
						<text style="font-size: 28rpx;color: #FFFFFF;" @click="store_list_fn()">搜索</text>
					</view>
				</view>
			</view>
			<scroll-view scroll-y="true" style="height:800rpx;" @scrolltolower='store_lists()' lower-threshold='50'>
				<view style="padding: 0px 6px;">
					<view class="flex-r-b-c" @tap.stop="store_true(v.id)"
						style="height:117px;width: 726rpx;border-color: #45806E;border-radius: 10px;border-style: solid;"
						v-for="(v,i) in store_list" :key='i' @click="store_active=i"
						:style="{borderWidth:store_active===i?'3rpx':'0px',padding:store_active===i?'0px 10px':'12px',boxShadow:store_active===i?'0px 3px 3px rgba(69, 128, 110, 0.22)':'none'}">
						<view class="flex-r-s-c" style="width:550rpx;">
							<view class="flex-c-c-c"
								style="width: 250rpx;height: 98px;box-shadow: 0px 3px 3px rgba(69, 128, 110, 0.22);border-radius: 6px;background-color: #FFFFFF;overflow: hidden;">
								<image :src="base.imgUrl+v.image" mode="widthFix"
									style="width: 250rpx;border-radius: 6px;">
								</image>
							</view>
							<view class="flex-c-b-s" style="height: 98px;margin-left: 30rpx;width: 250rpx;">
								<text class="one-line-ellipsis">{{v.name}}</text>
								<view class="flex-r-s-c">
									<image src="../../../static/icon/store.png" mode="widthFix" style="width: 11px;">
									</image>
									<text style="color: #999999;font-size: 12px;margin-left: 5px;">{{v.area}}</text>
								</view>
								<view class="flex-r-s-c">
									<image src="../../../static/icon/phone.png" mode="widthFix" style="width: 11px;">
									</image>
									<text style="color: #999999;font-size: 12px;margin-left: 5px;">{{v.mobile}}</text>
								</view>
								<text class="one-line-ellipsis"
									style="font-size: 12px;color: #5D5D5D;width: 100%;">{{v.address}}</text>
							</view>
						</view>
						<view class="flex-c-b-e" style="height: 98px;width: 150rpx;">
							<view class="flex-r-s-c">
								<image src="../../../static/icon/position1.png" mode="widthFix" style="width: 9px;">
								</image>
								<text style="color: #0F4C3A;font-size: 12px;margin-left: 5px;">{{v.distance}}km</text>
							</view>
							<u-button type="success " @click.stop="store_details_jump(v.id)"
								:custom-style="{backgroundColor: '#45806E',height:' 30px',width: '65px',marginBottom:' 23px',fontSize:'14px'}">
								详 情</u-button>
						</view>
					</view>
				</view>
				<view class="flex-c-c-c" style="height: 50rpx;">
					<text>{{store_list_text}}</text>
				</view>
			</scroll-view>
		</u-popup>
		<!-- 优惠劵 -->
		<u-popup v-model="is_coupon_show" mode="center" border-radius="12" height="366rpx" width="686rpx">
			<view class="couponBg flex-c-s-c">
				<view class="yhj_tit flex-c-c-c">点击领取</view>
				<view class="yhjbj_img flex-r-b-c">
					<view class="yhj_lq_text flex-r-b-c">
						<view class="flex-r-e-b">
							<text style="font-size: 20rpx;color:#C48A46;" v-if="coupon_obj.type==2">¥</text>
							<text
								style="font-size: 58rpx;color: #C48A46;margin-left: 6rpx;">{{coupon_obj.type==2?coupon_obj.price:`${coupon_obj.discount}折`}}</text>
						</view>
						<view class="flex-c-b-s" style="height: 66rpx;margin-left:28rpx;">
							<text style="font-size: 26rpx;color: #505050;">{{coupon_obj.title}}</text>
							<text
								style="font-size: 18rpx;color: #8E8E8E;">{{coupon_obj.limit_price>0?`满${coupon_obj.limit_price}元可用`:'无门槛限制'}}</text>
						</view>
					</view>
					<view class="yhj_lq_btn flex-c-c-c" @click="coupon_btn(coupon_obj.id)">
						领&nbsp;&nbsp;&nbsp;取
					</view>
				</view>
				<view class="yhj_text">{{coupon_obj.title}}</view>
				<image src="/static/icon/home_yhqbj.png" mode="widthFix"></image>
				<u-icon class="close" name="close" color="#FFF" size="28" @click="is_coupon_show=false"></u-icon>
			</view>
		</u-popup>
		<!-- 底部tabbar，组件内存在占位view最好放html最底部 -->
		<tabber :active='0'></tabber>
		<!-- <u-picker mode="region" v-model="true" :area-code='["13", "1303", "130304"]'></u-picker> -->
	</view>
</template>

<script>
	import tabber from '../../../components/tabbar.vue'
	import countDown from '../../../components/countDown.vue'
	export default {
		components: {
			tabber,
			countDown
		},
		data() {
			return {
				start: [0, 0],
				moveX: uni.getSystemInfoSync().windowWidth - 44,
				moveY: uni.getSystemInfoSync().windowHeight - 300,
				windowWidth: '',
				windowHeight: '',
				barHei: uni.getSystemInfoSync().statusBarHeight,
				hei: uni.getSystemInfoSync().windowHeight + uni.upx2px(100),
				base: this.$base,
				store_views: !uni.getStorageSync('store'), //刚进页面首页获取地址信息
				store_obj: { //门店列表
					num: 10,
					page: 0 //请求页数
				},
				store_list_text: '加载更多....', //门店列表加载提示
				jili: 0, //门店距离
				title: '', //门店名称
				message_show: false, //是否显示消息小红点
				list: [ /*轮播*/ ],
				click_active: null,
				jump: [ /*首页菜单*/ {
					icon: '/static/icon/order.png',
					name: '预约',
					// path: '/pages/tabBar/order/order',
					path: '/pages/tabBar/serviceReservation/serviceReservation',
					type: 'switchTab'
				}, {
					icon: '/static/icon/service.png',
					name: '商城',
					path: '/pages/tabBar/newService/newService',
					type: 'navigate'
				}, {
					icon: '/static/icon/aboutUs.png',
					name: '关于我们',
					type: 'navigate',
					path: '/store/aboutUs/aboutUs'
				}],
				jump1: [ /*首页活动跳转*/ ],
				arr: [],
				store_show: !uni.getStorageSync('store'), //门店弹框显示否
				userInfo: uni.getStorageSync('user_info'), // 用户登录信息
				store_keyword: '', //门店搜索框
				store_active: 0, //门店或搜索后的选择门店下标
				store_list: [],
				zz_store_obj: uni.getStorageSync('store_dz'), //门店最终选择
				share: {
					/*分享参数*/
				},
				is_coupon_show: false, //是否显示优惠劵
				coupon_obj: {}, //优惠劵
				sweiperHeight: uni.upx2px(850),
				isClose: true, // 关注 
				isShare: uni.getStorageSync('user_info') ? true : false,
			}
		},
		onLoad(el) {
			if (el?.userID) {
				uni.setStorageSync('scene_id', el.userID)
			}
			// if (!uni.getStorageSync('user_info')) {
			// 	this.store_fn()
			// }
			uni.setStorage({
				key: 'isTabBarOrder',
				data: false,
			})
			this.store_obj = {
				...this.store_obj,
				seach: null,
				...uni.getStorageSync('store')
			}
			this.store_lists()
			this.goods_homeGoods(this.zz_store_obj.id)
			let user_info = uni.getStorageSync('user_info');
			this.userInfo = user_info || null
			if (user_info) {
				this.sweiper_fns()
			}
			uni.$on('storedID', el => {
				console.log(el)
				console.log('门店id', Number(el.id))
				this.store_active = this.store_list.findIndex(res => res.id == Number(el.id))
				this.zz_store_obj.id = Number(el.id)
				this.store_true(el.id)
				this.sweiper_fns()
			})
		},
		onShareAppMessage(res) {
			return {
				title: this.share.title,
				path: this.share.path || `/pages/tabBar/home/home?userID=${this.userInfo.id}` ,
				imageUrl: this.share.imageUrl,
				desc: this.share.desc,
				content: this.share.content,
				success(res) {
					uni.showToast({
						title: '分享成功',
						icon: "none"
					})
					this.share = {}
					console.log(res)
				},
				fail(res) {
					uni.showToast({
						title: '分享失败',
						icon: 'none'
					})
				}
			}
		},
		methods: {
			drag_start(e) {
				this.start[0] = e.touches[0].clientX
				this.start[1] = e.touches[0].clientY
			},
			drag_hmove(e) {
				let el = e.touches[0],
					winWid = uni.getSystemInfoSync().windowWidth;
				if (el.clientX < 0) {
					el.clientX = 0
				}
				if (el.clientX > this.windowWidth) {
					el.clientX = this.windowWidth - 44
				}
				if (el.clientY < 150) {
					el.clientY = 150
				}
				if (el.clientY > this.windowHeight - 100) {
					el.clientY = this.windowHeight - 100
				}
				if (el.clientX > winWid - 44) {
					el.clientX = winWid - 44
				}
				this.moveX = el.clientX
				this.moveY = el.clientY
			},
			getUserFocusOn() {
				let that = this
				that.$api.user_focusOn().then(res => {
					console.log(res)
					res.data.data == 0 ? that.isClose = true : that.isClose = false
				})
			},

			imgs(i) {
				let index = i.currentTarget.dataset.index
				this.list[index].height = uni.upx2px(750) / i.detail.width * i.detail.height
			},
			isToday(str) { //判断时间戳是否为当天
				if (new Date(str).toDateString() === new Date().toDateString()) {
					//今天
					return true
				} else if (new Date(str) < new Date()) {
					//之前
					return false
				}
			},
			sweiperHeightFn(i) {
				this.sweiperHeight = this.list[i.detail.current].height
			},
			sweiper_fns() { //轮播请求
				this.$api.Goods_activeImage({
					store_id: uni.getStorageSync('store_dz').id
				}).then(res => {
					let obj = res.data.data.map(els => {
						els.img = this.base.imgUrl + els.image
						return els
					})
					this.list = obj
				})

				this.$api.Goods_active({
					store_id: uni.getStorageSync('store_dz').id
				}).then(res => {
					let obj = res.data.data.map(els => {
						els.kaishi = '11:00'
						return els
					})
					this.jump1 = res.data.data
				})
			},
			swiper_fn(el, res) { //轮播点击后
				let obj = res ? this.jump1 : this.list
				if (obj[el].ctype === 3) {
					uni.navigateTo({
						url: '/order/external/external?type=1&url=' + obj[el].url + '&cid=' + obj[el].cid
					})
				}
				else if(obj[el].ctype === 2) {
					uni.navigateTo({
						url: `/order/activityDetails/activityDetails?id=${obj[el].goods_id}&type=1`
					})
				} else if(obj[el].ctype === 1)  {
					switch (obj[el].type) {
						case 4:
							console.log('优惠券', obj[el])
							this.$api.Coupon_couponCount({
								region_coupon_id: obj[el].coupon_id
							}).then(res => { //查询优惠劵
								this.is_coupon_show = true
								this.coupon_obj = {
									...res.data.data,
									id: obj[el].coupon_id
								}
							})
							break;
						default:
							if (obj[el].id) {
								this.jumps_activ({
									goods_id: obj[el].goods_id,
									activity_type: obj[el].type,
									id: obj[el].id
								})
							} else {
								uni.navigateTo({
									url: `/order/activityDetails/activityDetails?id=${obj[el].goods_id}&type=1`
								})
							}
							break;
					}
				}
			},
			coupon_btn(id) { //领取优惠劵
				console.log(id)
				this.$api.Coupon_saveUserCoupon({
					region_coupon_id: id
				}).then(res => {
					uni.showToast({
						title: '领取成功',
						icon: 'none'
					})
					this.is_coupon_show = false
					this.coupon_obj = {}
				})
			},
			shareClick(item, v) {
				if (!uni.getStorageSync('user_info')) {
					uni.navigateTo({
						url: '/mine/login/login'
					})
				} else {
					this.share = {
						title: v.name,
						path: `/order/activityDetails/activityDetails?id=${v.goods_id}&type=1&userID=${this.userInfo.id}`,
						imageUrl: this.$base.imgUrl + v.image,
						desc: `我正在购买${v.name},快来看看吧!`,
						content: ''
					}
				}

			},
			store_fn() { //获取当前位置
				var that = this
				uni.getLocation({
					type: 'wgs84',
					success(res) {
						that.store_obj.lng = res.longitude //当前位置的经度
						that.store_obj.lat = res.latitude //当前位置的纬度
						that.store_views = false
						that.store_obj.page = 0
						that.store_list = []
						that.store_list_text = '加载更多....'
						that.store_lists()
						uni.setStorage({
							key: 'store',
							data: {
								lng: res.longitude,
								lat: res.latitude
							},
							success: function() {}
						});
					}
				});
			},
			store_lists() { //门店列表	
				let that = this
				if (that.store_list_text == '无更多门店') return
				that.store_list_text = that.store_list.length == 0 ? '暂无门店' : '加载中...'
				that.store_obj.page++
				that.$api.store_list(that.store_obj).then(res => {
					that.store_list_text = res.data.data.length == 0 || res.data.data.length < 10 ? '无更多门店' :
						'加载更多...'
					res.data.data.length == 0 ? '' : that.store_list = that.store_list.concat(res.data.data)
				})
			},
			getUserInfo() { //调用微信登录
				let that = this
				uni.getUserProfile({
					desc: 'Wexin', // 这个参数是必须的
					success: res => {
						uni.login({
							provider: 'weixin',
							success: res1 => {
								let obj = {
									nickname: res.userInfo.nickName,
									avatar: res.userInfo.avatarUrl,
									code: res1.code
								}
								that.$api.wx_login(obj).then(login => {
									console.log(login);
									//请求成功后的判断
									res = {
										...res,
										...login.data
									}
									uni.setStorage({
										key: 'user_info',
										data: res,
										success: function() {
											uni.showToast({
												title: '用户授权成功',
												icon: 'none'
											})
											that.store_true(uni.getStorageSync(
												'store_dz').id)
											that.$api.user_info().then(
												users => {
													console.log(users)
													res.id = users.data
														.data.id
													that.userInfo = res
													uni.setStorage({
														key: 'user_info',
														data: res
													});
													uni.setStorageSync(
														'focus_on',
														users.data.data
														.focus_on)
													that.sweiper_fns()
												})
										}
									});
								})
							}
						})
					},
					fail: err => {
						console.log(err)
					}
				})
			},
			goods_homeGoods(id) {
				let that = this
				if (!id) return
				that.$api.goods_homeGoods({
					store_id: id
				}).then(res => {
					console.log(res)
					this.arr = res.data.data
				})
			},
			store_true(id) { //门店弹框收起
				let that = this
				that.store_list.map(el => {
					if (el.id == id) {
						uni.setStorageSync('store_dz', el)
						that.zz_store_obj = el
						that.goods_homeGoods(el.id)
						that.sweiper_fns()
					}
				});
				!uni.getStorageSync('user_info') ? '' : that.saveUsetStore();
				that.store_show = false
				// uni.setStorage({
				// 	key: 'store_dz',
				// 	data: that.store_list[that.store_active],
				// 	success: function() {}
				// });
			},
			get_fn(data) {
				var arr = Object.keys(data);
				var str = "?";
				for (var i in data) {
					str += i;
					str += "=";
					str += data[i];
					str += "&";
				}
				return str.substr(0, str.length - 1)
			},
			saveUsetStore() {
				let that = this
				that.$api.store_saveUsetStore({
					store_id: uni.getStorageSync('store_dz').id
				}).then(res => {
					console.log(res)
				})
			},
			store_list_fn() { //门店搜索
				this.store_list = [];
				this.store_list_text = '加载中...'
				this.store_obj.page = 0;
				this.store_lists()
			},
			store_details_jump(id) {
				uni.navigateTo({
					url: `/store/Storedetails/Storedetails?id=${id}`
				})
			},
			jumps_activ(v) {
				uni.navigateTo({
					url: `/order/activityDetails/activityDetails?id=${v.goods_id}&type=${v.activity_type==1?2:(v.activity_type==2?3:1)}&activity_id=${v.id}&isone=${v.is_one == 1 ? 'false' : v.is_one == 2 ? 'true' : ''}`
				})
			},
			// tab 跳转
			goUrl(url) {
				if (url == '/pages/tabBar/serviceReservation/serviceReservation') {
					if (!uni.getStorageSync('user_info')) {
						uni.navigateTo({
							url: '/mine/login/login'
						})
					} else {
						// uni.switchTab({
						// 	url: url
						// })

						uni.navigateTo({
							url: url
						})
					}

				} else {
					uni.navigateTo({
						url: url
					})
				}
			},
			// 关注
			goExternal() {

				uni.navigateTo({
					url: !uni.getStorageSync('user_info') ? '/mine/login/login' : '/order/external/external?type=2'
				})

				// this.getUserFocusOn()
				// uni.navigateTo({
				// 	url: '/order/external/external'
				// })
			},
			customerService() { // 客服
				if (!uni.getStorageSync('user_info')) {
					uni.navigateTo({
						url: '/mine/login/login'
					})
				} else {
					wx.openCustomerServiceChat({
						extInfo: {
							url: 'https://work.weixin.qq.com/kfid/kfcfabe188f48472048'
						},
						corpId: 'ww482f5a23d248eb06',
						success(res) {
							console.log(res)
						},
						fail(err) {
							console.log(err)
						}
					})
				}



			}
		},
		onShow() {
			// 引用tabbar的页面隐藏自带tabbar,不改变四个tabbar的权重
			uni.hideTabBar()
			// this.goExternal()
			let user_info = uni.getStorageSync('user_info');
			this.userInfo = user_info || null
			if (user_info) {
				// this.sweiper_fns()
				this.getUserFocusOn()
			}
			const {
				windowWidth,
				windowHeight
			} = uni.getSystemInfoSync()
			this.windowWidth = windowWidth
			this.windowHeight = windowHeight
			this.store_fn()
		},
	}
</script>

<style lang="less" scoped>
	.isClose {
		bottom: calc(50px + constant(safe-area-inset-bottom));
		bottom: calc(50px + env(safe-area-inset-bottom));
		// top: calc(100rpx + 44px);
	}

	.safe-paddings {
		height: constant(safe-area-inset-bottom);
		height: env(safe-area-inset-bottom);
	}

	.btn_none {
		width: auto;
		height: auto;
		padding: 0;
		margin: 0;
		background-color: #FFF0;
		border: 0rpx;
	}

	.btn_none::after {
		border: none;
	}

	.page {
		background-color: #F5F5F5;
	}

	.status_bar {
		width: 100%;
	}

	.top_navigation {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		background-color: #FFFFFF;
		z-index: 999;

		.status_bar {
			width: 100%;
		}

		.navigation {
			width: 100%;
			height: 100rpx;
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;

			image {
				position: absolute;
				left: 60rpx;
				bottom: 25rpx;
				width: 50rpx;
			}
		}
	}

	.location_message {
		height: 50px;
		margin-top: 100rpx;
		padding: 0px 10px;

		.position {
			height: 40px;
			width: 70%;

			.position_text {
				margin-left: 5px;

				.position_text1 {
					font-size: 14px;
					color: #363636;
				}

				text {
					color: #888888;
					font-size: 12px;
				}
			}
		}

		.message_red {
			position: relative;

			view {
				position: absolute;
				right: -2px;
				top: -2px;
				width: 6px;
				height: 6px;
				background: #E8351E;
				border-radius: 50%;
			}
		}
	}

	.swiper_bar {
		height: 560rpx;
		z-index: 99;
	}

	.menu_taber {
		width: 125px;
		height: 90px;

		text {
			font-size: 14px;
			color: #363636;
			margin-top: 4px;
		}
	}

	.couponBg {
		height: 366rpx;
		width: 686rpx;
		background-color: #FF5929;
		position: relative;
		z-index: 999;

		.yhj_tit {
			font-size: 36rpx;
			color: #FFFFFF;
			height: 80rpx;
			margin-top: 20rpx;
			z-index: 1001;
		}

		.yhjbj_img {
			margin-top: 40rpx;
			width: 594rpx;
			height: 139rpx;
			background-image: url(../../../static/mine/yhqbj.png);
			background-size: 100% 100%;
			background-repeat: no-repeat;
			z-index: 1001;

			// position: relative;
			.yhj_lq_btn {
				width: 168rpx;
				height: 52rpx;
				background: linear-gradient(157deg, #EBCB8A 0%, #E8BE6C 100%);
				border-radius: 30rpx;
				color: #916724;
				font-size: 22rpx;
				font-weight: bold;
				margin-right: 38rpx;
			}

			.yhj_lq_text {
				margin-left: 34rpx;
				height: 76rpx;
			}
		}

		.yhj_text {
			margin-top: 20rpx;
			font-size: 23rpx;
			color: #FFFFFF;
			z-index: 1001;
		}

		image {
			height: 366rpx;
			width: 686rpx;
			position: absolute;
			left: 0;
			top: 0;
			z-index: 1000;
		}

		.close {
			position: absolute;
			right: 15rpx;
			top: 15rpx;
			z-index: 1001;
		}
	}
</style>
